package com.wanshi.entity;

import java.io.Serializable;
import java.sql.Date;
import java.util.HashMap;
import java.util.Map;


public class User implements Serializable {
	
	public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
	public static final String NAME_AND_PSD = "^\\w{4,20}$";

	private int id;
	private String username;
	private String password;
	private String nickname;
	private String email;
	private int state;//用户状态   激活   未激活
	private String statecode;//激活码
	
	private Date regtime;//注册时间
	private int role_id;

	public int getRole_id() {
		return role_id;
	}

	public void setRole_id(int role_id) {
		this.role_id = role_id;
	}

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getNickname() {
		return nickname;
	}
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	public String getStatecode() {
		return statecode;
	}
	public void setStatecode(String statecode) {
		this.statecode = statecode;
	}
	public Date getRegtime() {
		return regtime;
	}
	public void setRegtime(Date regtime) {
		this.regtime = regtime;
	}

	public User() {
		super();
	}

	

	//定义方法校验Cust对象
		public Map<String,String> checkCust(){
			 Map<String,String> map = new HashMap<String,String>();

			//手机号     邮箱    用户名 密码必须 字母数字或下划线  4-20
			if(this.username == null || username.equals("")){
				map.put("username", "姓名不能为空");
			}else if(!username.matches(NAME_AND_PSD)){
				map.put("username", "用户名格式不正确,必须是4-20位字母数字或下划线组成");
			}
			if(password == null || password.equals("")){
				map.put("password", "密码不能为空");
			}else if(!password.matches(NAME_AND_PSD)){
				map.put("password", "密码格式不正确,必须是4-20位字母数字或下划线组成");
			}
			if(nickname == null || nickname.equals("")){
				map.put("nickname", "昵称不能为空");
			}
			if(email == null || email.equals("")){
				map.put("email", "电子邮箱不能为空");
			}else if(!email.matches(REGEX_EMAIL)){
				map.put("email", "邮箱格式不正确");
			}
			return map;
		}
		
	
	

}
